
//2367.等差三元组的数目
class Solution {
public:
    int arithmeticTriplets(vector<int>& nums, int diff) {
        int n=nums.size();
        int left=0,right=2,ret=0;
        for(int i=0;i<n&&right<n;i++)
        {
            //进行左右两边的查找
            while(nums[left]<nums[i]-diff) left++;
            while(right<n&&nums[right]<nums[i]+diff) right++;

            if(right<n&&nums[left]==nums[i]-diff&&nums[right]==nums[i]+diff) ret++;
        }
        return ret;
    }
};